package com.media.themovieworld.screen.detail;

import java.util.ArrayList;

import android.app.Activity;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.TextView;

import com.media.themovieworld.R;
import com.media.themovieworld.common.adapter.BaseListAdapter;
import com.media.themovieworld.common.fragment.MovieWorldScreen;
import com.media.themovieworld.model.FilmPartModel;
import com.media.themovieworld.player.FilmPartManage;
import com.media.themovieworld.player.MoviePlayerActivity;
import com.media.themovieworld.widget.pullandloadmore.LoadMoreListView;

public class WatchMoviePagerScreen extends MovieWorldScreen{

	private LoadMoreListView mLoadMoreListView;
	
	@Override
	protected View onCreateContentView(LayoutInflater inflater,
			ViewGroup container) {
		View root = inflater.inflate(R.layout.tmw__list_efilm_screen, container,false);
		mLoadMoreListView = (LoadMoreListView) root.findViewById(R.id.tmw__list_efilm_list);
		loadDatas();
		return root;
	}
	
	private void loadDatas() {
		ArrayList<FilmPartModel> mListDatas = FilmPartManage.getInstance().getCurrentListFilmPart();
		if(mListDatas == null) return;
		FilmPartAdapter adapter = new FilmPartAdapter(getActivity(), mListDatas);
		mLoadMoreListView.setAdapter(adapter);
		mLoadMoreListView.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> arg0, View arg1, int pos,
					long arg3) {
				Intent intent = new Intent(getActivity(), MoviePlayerActivity.class);
				intent.putExtra("index", pos);
				getActivity().startActivity(intent);
			}
		});
	}
	
	public class FilmPartAdapter extends BaseListAdapter<FilmPartModel>{

		public FilmPartAdapter(Activity activity, ArrayList<FilmPartModel> datas) {
			super(activity, datas);
		}

		@Override
		public View getView(int position, View convertView, ViewGroup arg2) {
			View row = convertView;
			if (row == null) {
				row = LayoutInflater.from(mActivity).inflate(R.layout.list_link_adapter, null);
			}
			TextView tv = (TextView) row.findViewById(R.id.tLink);
			tv.setText(getItem(position).name);
			return row;
		}
		
	}

	
}
